package com.hxx.demo.service;


import com.hxx.demo.dao.RoomDao;
import com.hxx.demo.entity.GridRequest;
import com.hxx.demo.entity.Room;
import com.hxx.demo.utils.ParamsInitUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Hxx
 */
@Service
@Transactional
public class RoomService {
    @Autowired
    private RoomDao roomDao;


    /**
     * @return void
     * @Author Hxx
     * @Description //TODO 添加宿舍信息
     * @Date 9:31 2019/11/7
     * @Param [room]
     **/
    public int addRoom(Room room) {
        return roomDao.addRoom(room);
    }


    /**
     * @return java.util.List<com.hxx.demo.entity.Room>
     * @Author Hxx
     * @Description //TODO 数据初始化
     * @Date 13:54 2020/2/26
     * @Param []
     **/
    public List<Room> findAll() {
        return roomDao.find();
    }

    /**
     * @return void
     * @Author Hxx
     * @Description //TODO 删除宿舍信息
     * @Date 9:42 2019/11/7
     * @Param [id]
     **/
    public int delRoom(String id) {
        return roomDao.deltRoom(id);
    }


    /**
     * @return int
     * @Author Hxx
     * @Description //TODO 更新宿舍信息
     * @Date 15:48 2019/12/11
     * @Param [room]
     **/
    public int editRoom(Room room) {
        return roomDao.editRoom(room);
    }


    /**
     * @return java.util.List<com.hxx.demo.entity.Room>
     * @Author Hxx
     * @Description //TODO 根据关键字查找宿舍信息
     * @Date 16:02 2019/12/11
     * @Param [gridJson]
     **/
    public List<Room> getGrid(GridRequest gridJson) {
        ParamsInitUtils paramsInitUtils = new ParamsInitUtils();
        String sql = paramsInitUtils.initParams(gridJson, "room");
        List<Room> rooms = this.roomDao.findBykeywords(sql);
        return rooms;
    }


    /**
     * @return java.util.List<com.hxx.demo.entity.Room>
     * @Author Hxx
     * @Description //TODO  宿舍号下拉菜单
     * @Date 14:02 2019/12/23
     * @Param []
     **/
    public List<Room> getRoom() {
        return roomDao.findMeanRoomId();
    }

    /**
     * @return java.util.List<com.hxx.demo.entity.Room>
     * @Author Hxx
     * @Description //TODO  楼号下拉菜单
     * @Date 14:02 2019/12/23
     * @Param []
     **/
    public List<Room> getBuild() {
        {
            return roomDao.findMeanBuildId();
        }
    }

    /**
     * @return int
     * @Author Hxx
     * @Description //TODO 批量删除
     * @Date 15:50 2019/12/27
     * @Param [ids]
     **/
    public boolean deleteBatch(String ids) {
        String[] split = ids.split(",");
        return roomDao.deleteBatch(split) == split.length;
    }

    /**
     * @return com.hxx.demo.entity.Room
     * @Author Hxx
     * @Description //TODO 根据roomId查找宿舍信息
     * @Date 15:20 2019/12/28
     * @Param [roomId]
     **/
    public Room findByRoomId(Integer buildId, String roomId) {
        return roomDao.findByRoomId(buildId, roomId);
    }

    public Room findById(String id) {
        return roomDao.findById(id);
    }


}
